/*********************************************************************
	Rhapsody	: 7.6
	Login		: Pawel
	Component	: DefaultComponent
	Configuration 	: DefaultConfig
	Model Element	: OuterDoor
//!	Generated Date	: Sun, 27, Nov 2011 
	File Path	: DefaultComponent/DefaultConfig/CargoLiftSystem/OuterDoor.java
*********************************************************************/

package CargoLiftSystem;

//## link itsIDoorsLock 
import Hardware.IDoorsLock;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import com.ibm.rational.rhapsody.animation.*;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;
//## auto_generated
import com.ibm.rational.rhapsody.animcom.animMessages.*;

//----------------------------------------------------------------------------
// CargoLiftSystem/OuterDoor.java                                                                  
//----------------------------------------------------------------------------

//## package CargoLiftSystem 


//## class OuterDoor 
public class OuterDoor implements RiJStateConcept, Animated {
    
    //#[ ignore
    // Instrumentation attributes (Animation)
    private Animate animate;
    
    public static AnimClass animClassOuterDoor = new AnimClass("CargoLiftSystem.OuterDoor",false);
    //#]
    
    public Reactive reactive;		//## ignore 
    
    protected IDoorsLock itsIDoorsLock;		//## link itsIDoorsLock 
    
    protected InnerDoor itsInnerDoor;		//## link itsInnerDoor 
    
    protected Lift itsLift;		//## link itsLift 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    public static final int readyToClose=1;
    public static final int open=2;
    public static final int closing=3;
    public static final int closed=4;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    //## auto_generated 
    public  OuterDoor(RiJThread p_thread) {
        try {
            animInstance().notifyConstructorEntered(animClassOuterDoor.getUserClass(),
               new ArgData[] {
               });
        
        reactive = new Reactive(p_thread);
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## auto_generated 
    public IDoorsLock getItsIDoorsLock() {
        return itsIDoorsLock;
    }
    
    //## auto_generated 
    public void setItsIDoorsLock(IDoorsLock p_IDoorsLock) {
        itsIDoorsLock = p_IDoorsLock;
        if(p_IDoorsLock != null)
            {
                animInstance().notifyRelationAdded("itsIDoorsLock", p_IDoorsLock);
            }
        else
            {
                animInstance().notifyRelationCleared("itsIDoorsLock");
            }
    }
    
    //## auto_generated 
    public InnerDoor getItsInnerDoor() {
        return itsInnerDoor;
    }
    
    //## auto_generated 
    public void __setItsInnerDoor(InnerDoor p_InnerDoor) {
        itsInnerDoor = p_InnerDoor;
        if(p_InnerDoor != null)
            {
                animInstance().notifyRelationAdded("itsInnerDoor", p_InnerDoor);
            }
        else
            {
                animInstance().notifyRelationCleared("itsInnerDoor");
            }
    }
    
    //## auto_generated 
    public void _setItsInnerDoor(InnerDoor p_InnerDoor) {
        if(itsInnerDoor != null)
            {
                itsInnerDoor._removeItsOuterDoor(this);
            }
        __setItsInnerDoor(p_InnerDoor);
    }
    
    //## auto_generated 
    public void setItsInnerDoor(InnerDoor p_InnerDoor) {
        if(p_InnerDoor != null)
            {
                p_InnerDoor._addItsOuterDoor(this);
            }
        _setItsInnerDoor(p_InnerDoor);
    }
    
    //## auto_generated 
    public void _clearItsInnerDoor() {
        animInstance().notifyRelationCleared("itsInnerDoor");
        itsInnerDoor = null;
    }
    
    //## auto_generated 
    public Lift getItsLift() {
        return itsLift;
    }
    
    //## auto_generated 
    public void setItsLift(Lift p_Lift) {
        itsLift = p_Lift;
        if(p_Lift != null)
            {
                animInstance().notifyRelationAdded("itsLift", p_Lift);
            }
        else
            {
                animInstance().notifyRelationCleared("itsLift");
            }
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = false;
        done = reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive implements AnimatedReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            return true;
        }
        
        //## statechart_method 
        public void rootState_add(AnimStates animStates) {
            animStates.add("ROOT");
            switch (rootState_subState) {
                case closed:
                {
                    closed_add(animStates);
                }
                break;
                case open:
                {
                    open_add(animStates);
                }
                break;
                case readyToClose:
                {
                    readyToClose_add(animStates);
                }
                break;
                case closing:
                {
                    closing_add(animStates);
                }
                break;
                default:
                    break;
            }
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (rootState_active) {
                case closed:
                {
                    res = closed_takeEvent(id);
                }
                break;
                case open:
                {
                    res = open_takeEvent(id);
                }
                break;
                case readyToClose:
                {
                    res = readyToClose_takeEvent(id);
                }
                break;
                case closing:
                {
                    res = closing_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## statechart_method 
        public void readyToClose_add(AnimStates animStates) {
            animStates.add("ROOT.readyToClose");
        }
        
        //## statechart_method 
        public void open_add(AnimStates animStates) {
            animStates.add("ROOT.open");
        }
        
        //## statechart_method 
        public void closing_add(AnimStates animStates) {
            animStates.add("ROOT.closing");
        }
        
        //## statechart_method 
        public void closed_add(AnimStates animStates) {
            animStates.add("ROOT.closed");
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
        }
        
        //## statechart_method 
        public void closing_enter() {
            animInstance().notifyStateEntered("ROOT.closing");
            rootState_subState = closing;
            rootState_active = closing;
            closingEnter();
        }
        
        //## statechart_method 
        public void closedExit() {
        }
        
        //## statechart_method 
        public int closing_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(doorClosed.doorClosed_CargoLiftSystem_id))
                {
                    res = closingTakedoorClosed();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void readyToClose_exit() {
            popNullConfig();
            readyToCloseExit();
            animInstance().notifyStateExited("ROOT.readyToClose");
        }
        
        //## statechart_method 
        public int closedTakeOpenDoors() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("1");
            closed_exit();
            //#[ transition 1 
            itsInnerDoor.gen(new evDoorsOpen());
            //#]
            open_entDef();
            animInstance().notifyTransitionEnded("1");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public int open_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = openTakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void closed_entDef() {
            closed_enter();
        }
        
        //## statechart_method 
        public void closingEnter() {
        }
        
        //## statechart_method 
        public int openTakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("2");
            open_exit();
            readyToClose_entDef();
            animInstance().notifyTransitionEnded("2");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void open_entDef() {
            open_enter();
        }
        
        //## statechart_method 
        public int readyToCloseTakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("4");
            readyToClose_exit();
            closing_entDef();
            animInstance().notifyTransitionEnded("4");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void readyToClose_enter() {
            animInstance().notifyStateEntered("ROOT.readyToClose");
            pushNullConfig();
            rootState_subState = readyToClose;
            rootState_active = readyToClose;
            readyToCloseEnter();
        }
        
        //## statechart_method 
        public void openEnter() {
        }
        
        //## statechart_method 
        public int readyToCloseTakeevObstacleInDoors() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("3");
            readyToClose_exit();
            //#[ transition 3 
            itsInnerDoor.gen(new evObstacleInDoors());
            //#]
            open_entDef();
            animInstance().notifyTransitionEnded("3");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void readyToClose_entDef() {
            readyToClose_enter();
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void closing_exit() {
            closingExit();
            animInstance().notifyStateExited("ROOT.closing");
        }
        
        //## statechart_method 
        public void openExit() {
        }
        
        //## statechart_method 
        public void closedEnter() {
        }
        
        //## statechart_method 
        public void open_exit() {
            popNullConfig();
            openExit();
            animInstance().notifyStateExited("ROOT.open");
        }
        
        //## statechart_method 
        public void rootState_enter() {
            animInstance().notifyStateEntered("ROOT");
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public int closed_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(OpenDoors.OpenDoors_CargoLiftSystem_id))
                {
                    res = closedTakeOpenDoors();
                }
            
            return res;
        }
        
        //## statechart_method 
        public int closingTakedoorClosed() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("5");
            closing_exit();
            closed_entDef();
            animInstance().notifyTransitionEnded("5");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void closingExit() {
        }
        
        //## statechart_method 
        public void closing_entDef() {
            closing_enter();
        }
        
        //## statechart_method 
        public int readyToClose_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(evObstacleInDoors.evObstacleInDoors_CargoLiftSystem_id))
                {
                    res = readyToCloseTakeevObstacleInDoors();
                }
            else if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = readyToCloseTakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void closed_exit() {
            closedExit();
            animInstance().notifyStateExited("ROOT.closed");
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
            animInstance().notifyTransitionStarted("0");
            closed_entDef();
            animInstance().notifyTransitionEnded("0");
        }
        
        //## statechart_method 
        public void closed_enter() {
            animInstance().notifyStateEntered("ROOT.closed");
            rootState_subState = closed;
            rootState_active = closed;
            closedEnter();
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
        //## statechart_method 
        public void open_enter() {
            animInstance().notifyStateEntered("ROOT.open");
            pushNullConfig();
            rootState_subState = open;
            rootState_active = open;
            openEnter();
        }
        
        //## statechart_method 
        public void readyToCloseExit() {
        }
        
        //## statechart_method 
        public void readyToCloseEnter() {
        }
        
        /**  methods added just for design level debugging instrumentation */
        public boolean startBehavior() {
            try {
              animInstance().notifyBehavioralMethodEntered("startBehavior",
                  new ArgData[] {
                   });
              return super.startBehavior();
            }
            finally {
              animInstance().notifyMethodExit();
            }
        }
        public int takeEvent(RiJEvent event) { 
            try { 
              //animInstance().notifyTakeEvent(new AnimEvent(event));
              animInstance().notifyBehavioralMethodEntered("takeEvent",
                  new ArgData[] { new ArgData(RiJEvent.class, "event", event.toString())
                   });
              return super.takeEvent(event); 
            }
            finally { 
              animInstance().notifyMethodExit();
            }
        }
        /**  see com.ibm.rational.rhapsody.animation.AnimatedReactive interface */
        public AnimInstance animInstance() { 
            return OuterDoor.this.animInstance(); 
        }
        
    }
    //#[ ignore
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimClass getAnimClass() { 
        return animClassOuterDoor; 
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public Object getFieldValue(java.lang.reflect.Field f, Object userInstance) { 
         Object obj = null;
         try {
             obj = f.get(userInstance);
         } catch(Exception e) {
              System.err.println("Exception: getting Field value: " + e);
              e.printStackTrace();
         }
         return obj;
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimInstance animInstance() {
        if (animate == null) 
            animate = new Animate(); 
        return animate; 
    } 
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addAttributes(AnimAttributes msg) {
        
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addRelations(AnimRelations msg) {
        
        msg.add("itsIDoorsLock", false, true, itsIDoorsLock);
        msg.add("itsLift", false, true, itsLift);
        msg.add("itsInnerDoor", false, true, itsInnerDoor);
    }
    /** An inner class added as instrumentation for animation */
    public class Animate extends AnimInstance { 
        public  Animate() { 
            super(OuterDoor.this); 
        } 
        public void addAttributes(AnimAttributes msg) {
            OuterDoor.this.addAttributes(msg);
        }
        public void addRelations(AnimRelations msg) {
            OuterDoor.this.addRelations(msg);
        }
        
        public void addStates(AnimStates msg) {
            if ((reactive != null) && (reactive.isTerminated() == false))
              reactive.rootState_add(msg);
        }
        
    } 
    //#]
    
}
/*********************************************************************
	File Path	: DefaultComponent/DefaultConfig/CargoLiftSystem/OuterDoor.java
*********************************************************************/

